package org.henau.EmergencyHandlerChain;

// 6. 责任链构建器 (EmergencyHandlerChain.java)
public class EmergencyHandlerChain {
    private final EmergencyHandler chainHead;

    public EmergencyHandlerChain() {
        // 创建处理器实例
        ObstacleHandler obstacleHandler = new ObstacleHandler();
        EmergencyStopHandler stopHandler = new EmergencyStopHandler();

        // 构建处理链：障碍处理 → 急停处理
        obstacleHandler.setNextHandler(stopHandler);

        this.chainHead = obstacleHandler;
    }

    public void processEvent(EmergencyEvent event) {
        System.out.println("\n=== 处理事件: " + event + " ===");
        chainHead.handleEvent(event);

        if (!event.isResolved()) {
            System.out.println("⚠️ 警告: 事件未完全处理!");
        } else {
            System.out.println("✅ 事件已成功处理");
        }
    }
}